﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Objects.DataClasses;
using System.Linq;

using IdeaNMR.Shared;
using IdeaNMR.Shared.Utils;

namespace IdeaNMR.Web.Core
{
    /// <summary>
    /// Essential that Sample Implements the Interface.
    /// The interface implementation is inherited from HardObject
    /// </summary>
    public partial class Sample : IHardObjectRelations
    {
    }

    /// <summary>
    /// Essential that Spectrometer Implements the Interface.
    /// The interface implementation is inherited from HardObject
    /// </summary>
    public partial class Spectrometer : IHardObjectRelations
    {
    }


    public partial class BaseObject
    {
        /// <summary>
        /// Returns ComponentType of an NMRObject
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the input parameter is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when NMRObject is wrong.</exception>
        public EntityType GetEntityType()
        {
            if (this is PulseProgram) return EntityType.PulseProgram;
            if (this is Wave) return EntityType.WaveShape;
            if (this is Cpd) return EntityType.Cpd;
            if (this is Script) return EntityType.Script;
            if (this is Sample) return EntityType.Sample;
            if (this is Spectrometer) return EntityType.Spectrometer;

            throw new ArgumentException("Incorrect object type.");
        }
    }

    public partial class NMRObject
    {
        public string FirstAuthorLastname
        {
            get
            {
                User u = this.Authors.Where(a => a.Index == 0).FirstOrDefault().User;
                return u.Lastname == null ? string.Empty : u.Lastname;
            }
        }
    }

    /// <summary>
    /// Specifies navigation properties common for HardObject derived objects.
    /// </summary>
    public interface IHardObjectRelations
    {
        User User
        { get; set; }
        System.Data.Objects.DataClasses.EntityReference<User> UserReference
        { get; set; }

        System.Data.Objects.DataClasses.EntityCollection<Experiment> Experiments
        { get; set; }

    }
}
